package com.wc.算法提高课.B第二章_搜索.IDAStar.排书;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/30 15:21
 * @description https://www.acwing.com/problem/content/182/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 20;
    static int[] q = new int[N];
    static int[][] w = new int[5][N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            for (int i = 0; i < n; i++) q[i] = sc.nextInt();
            int depth = 0;
            while (!dfs(0, depth) && depth < 5) depth++;
            if (depth >= 5) out.println("5 or more");
            else out.println(depth);
        }
        out.flush();
    }

    static boolean dfs(int depth, int maxDepth) {
        if (depth + f() > maxDepth) return false;
        if (f() == 0) return true;

        // 挑选的长度
        for (int len = n - 1; len >= 0; len--) {
            // 挑选的左结点
            for (int l = 0; l + len - 1 < n; l++) {
                // 挑选的右结点
                int r = l + len - 1;
                for (int k = r + 1; k < n; k++) {
                    System.arraycopy(q, 0, w[depth], 0, n);
                    int y = l;
                    for (int x = r + 1; x <= k; x++, y++) q[y] = w[depth][x];
                    for (int x = l; x <= r; x++, y++) q[y] = w[depth][x];
                    if (dfs(depth + 1, maxDepth)) return true;
                    System.arraycopy(w[depth], 0, q, 0, n);
                }
            }
        }
        return false;
    }

    static int f() {
        int tot = 0;
        for (int i = 0; i + 1 < n; i++) {
            if (q[i] != q[i + 1] - 1) tot++;
        }
        return (tot + 2) / 3;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
